www.gusucode.com > VC++ 酒店管理系统-源码程序 > VC++ 酒店管理系统-源码程序/code/hotel2003/ChooseServer.cpp
// ChooseServer.cpp : implementation file // Download by http://www.NewXing.com #include "stdafx.h" #include "qq.h" #include "ChooseServer.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CChooseServer dialog CChooseServer::CChooseServer(CWnd* pParent /*=NULL*/) : CDialog(CChooseServer::IDD, pParent) { //{{AFX_DATA_INIT(CChooseServer) m_PaidType = -1; //}}AFX_DATA_INIT m_DefaultSum=0.00f; bStriked=false; } void CChooseServer::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CChooseServer) DDX_Control(pDX, IDC_EMPLOYER, EmployerCode); DDX_Control(pDX, IDC_SERVERSUM, Sum); DDX_Control(pDX, IDC_SERVERREBATE, Rebate); DDX_Control(pDX, IDC_SERVERPAID, Paid); DDX_Control(pDX, IDC_SERVERNUM, Num); DDX_Control(pDX, IDC_SERVERLIST, ServerList); DDX_Control(pDX, IDC_SERVERBILLLIST, ServerBillList); DDX_Control(pDX, IDC_HANDCODE, HandCode); DDX_Control(pDX, IDC_BILLCODEINSERVER, BillCode); DDX_Radio(pDX, IDC_RADIO1, m_PaidType); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CChooseServer, CDialog) //{{AFX_MSG_MAP(CChooseServer) ON_BN_CLICKED(IDC_ADD, OnAdd) ON_BN_CLICKED(IDC_DELETE, OnDelete) ON_BN_CLICKED(IDC_RADIO1, OnRadio) ON_BN_CLICKED(IDC_RADIO2, OnRadio) ON_BN_CLICKED(IDC_UPDATESERVERDATA, OnUpdatedata) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CChooseServer message handlers BOOL CChooseServer::OnInitDialog() {//初始化数据成员 CDialog::OnInitDialog(); HICON m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME2); this->SetIcon(m_hIcon,true);//设置对话框图标 // TODO: Add extra initialization here //显示帐单号码 CCreateBillCode billcode; BillCode.SetWindowText(billcode.GenereBillCode()); //显示服务项目和价格 if(!m_ServerInfoSet.Open()) { MessageBox("打开数据库失败!","数据库错误",MB_OK); return false; } m_ServerInfoSet.MoveFirst();//移动到第一条记录 while (!m_ServerInfoSet.IsEOF()) { CString strServerName=""; float nServerPrice=0.00f; strServerName=m_ServerInfoSet.m_ServerName; nServerPrice=m_ServerInfoSet.m_ServerPrice; CString str; str.Format("%6.00f",nServerPrice); strServerName=strServerName+" "+str; ServerList.AddString(strServerName); m_ServerInfoSet.MoveNext();//移动到下一条记录 } m_ServerInfoSet.Close();//关闭数据库 //设置缺省折扣率 Rebate.SetWindowText("1"); //将钱的总数设置为0 Sum.SetWindowText("0"); ///Paid无效话 Paid.SetWindowText("0"); Paid.EnableWindow(FALSE); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CChooseServer::OnOK() { // TODO: Add extra validation here /////保存数据到数据库中 OnUpdatedata();//自动更新数据,防止因为忘记更新或者其他的原因产生误操作 CString strHandCode; HandCode.GetWindowText(strHandCode); if(strHandCode=="") { MessageBox("请输入手牌号!","数据为空错误",MB_OK); return; } /////如果选择的是"现结"方式,而已经付的金额为<0则提示输入错误 CString strPaidTemp=""; Paid.GetWindowText(strPaidTemp);//得到已经付的款 if(bStriked) { if(strPaidTemp==""||strPaidTemp=="0") { MessageBox("你可能输入错误,客人已经付的款应该大于0!!","输入信息错误",MB_OK); return; } } //查找客人数据库中是否存在这个手牌号 if(!m_GuestInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE)) { AfxMessageBox("打开数据库失败!"); return; } m_GuestInfoSet.MoveFirst(); bool bhas=false; while(!m_GuestInfoSet.IsEOF()) { if(m_GuestInfoSet.m_HandCode==strHandCode) { ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////// bhas=true;//存在这条记录 break; } m_GuestInfoSet.MoveNext();//移动到下一条记录 } if(!bhas) { MessageBox("你输入的手牌号不正确!","输入信息错误",MB_OK); m_GuestInfoSet.Close();//关闭数据库 return; } m_GuestInfoSet.Close();//关闭数据库 ////////查询完毕 ////////////////////////////////////////////////////////////////////////// /////将数据保存到相应的数据库中 /////写BillInfoSet表 if(!m_BillInfoSet.Open()) {//打开数据库失败处理异常 MessageBox("打开数据库失败!","数据库错误",MB_OK); return; } /////新增加一条帐单的记录 m_BillInfoSet.AddNew(); /////数据填充 CString strBillCode,strSum,strPaid,strRebate; BillCode.GetWindowText(strBillCode); m_BillInfoSet.m_BillCode=strBillCode;//帐单号码 m_BillInfoSet.m_HandCode=strHandCode;//客人手牌 Sum.GetWindowText(strSum); char* s=strSum.GetBuffer(strSum.GetLength()); long nSum=atol(s); m_BillInfoSet.m_Sum=nSum;//应付总数 Paid.GetWindowText(strPaid); s=strPaid.GetBuffer(strPaid.GetLength()); long nPaid=atol(s); m_BillInfoSet.m_Paid=nPaid;//实付总数 Rebate.GetWindowText(strRebate); m_BillInfoSet.m_Rebate=strRebate;//折扣率there is a bug!!!! m_BillInfoSet.m_Striked=bStriked;//是否已经付款 m_BillInfoSet.Update();//数据更新 m_BillInfoSet.Close(); //关闭数据库 ////////////////////////////////////////////////////////////////////////// // 开始写BillContentInfo表,记录这个帐单的具体消费情况 if(!m_BillContentInfoSet.Open()) { MessageBox("打开数据库失败!","数据库错误",MB_OK); return; } m_BillContentInfoSet.AddNew();//新增一条记录 CString strBillContent=""; for(int i=0;i<ServerBillList.GetCount();i++) { CString strTemp=""; ServerBillList.GetText(i,strTemp); strBillContent=strBillContent+strTemp+","; } CString strBillcode; BillCode.GetWindowText(strBillcode); m_BillContentInfoSet.m_BillCode=strBillcode; m_BillContentInfoSet.m_BillContent=strBillContent; m_BillContentInfoSet.Update();//更新数据库,将缓冲区的数据写入数据库中 m_BillContentInfoSet.Close();//关闭数据库 CDialog::OnOK(); } void CChooseServer::OnCancel() { // TODO: Add extra cleanup here CDialog::OnCancel(); } void CChooseServer::OnAdd() { // TODO: Add your control notification handler code here int nCurSel=ServerList.GetCurSel(); if(nCurSel==-1) { MessageBox("请选择至少一种服务!","数据为空错误",MB_OK); return; } CString strServerNum; Num.GetWindowText(strServerNum); if(strServerNum==""||strServerNum=="0") { MessageBox("数量至少要为一","数据为空错误",MB_OK); return; } CString strServerName=""; ServerList.GetText(nCurSel,strServerName);//得到文本 char* s=strServerName.GetBuffer(strServerName.GetLength()); char* str=strtok(s," ");//得到菜的名字 bool bSame=false; for(int i=0;i<ServerBillList.GetCount();i++) { CString strTemp=""; ServerBillList.GetText(i,strTemp);//得到文本 char* temp=strTemp.GetBuffer(strTemp.GetLength());//得到缓冲区字符 char* bSameText=strtok(temp," "); if(*bSameText==*str)//找到一个相同的项目 { bSame=true; MessageBox("你已经选了这个服务!","选择错误",MB_OK); return; } } if(!bSame)//若没有相同的项目则添加新的记录 { strServerName=str;//构造显示文本 CString strEmployerCode;//服务员ID EmployerCode.GetWindowText(strEmployerCode); if(strEmployerCode=="") {//服务员ID为空 MessageBox("请输入服务人员的ID","数据为空错误",MB_OK); return; } ///查询服务员表看看是否存在这个服务员 CString SQLstr=""; bool bHasTheEmployerCode=false; CString strEmployerName=""; if(!m_EmployerInfoSet.Open()) { MessageBox("打开数据库失败!","数据库错误",MB_OK); return; } m_EmployerInfoSet.MoveFirst(); while (!m_EmployerInfoSet.IsEOF()) { if(m_EmployerInfoSet.m_EmployerCode==strEmployerCode) { bHasTheEmployerCode=true; strEmployerName=m_EmployerInfoSet.m_Name; break; } m_EmployerInfoSet.MoveNext();//移动到下一条记录 } m_EmployerInfoSet.Close();//关闭数据库 if(bHasTheEmployerCode) { strServerName=strServerName+" "+strServerNum+" "+strEmployerName; ServerBillList.AddString(strServerName);//添加字符窜 } else { MessageBox("该服务员的代号不存在!","信息错误",MB_OK); return; } } /////////////////////添加一个项目完成 //////////////////////////////////////////////////////////////////// /*########################计算当前应付的总款######################### ####################################################################*/ float MoneySum=0;//总钱数目 for( i=0;i<ServerBillList.GetCount();i++) { //取得当前文本 CString BillListText=""; ServerBillList.GetText(i,BillListText);//取得文本 //将取得的文本进行转换(char*) char* billlistText=BillListText.GetBuffer(BillListText.GetLength()); char* ServerNameInBillList,*ServerNumInBillList; //分别取得对应的数据 ServerNameInBillList=strtok(billlistText," ");//食物名字 ServerNumInBillList=strtok(NULL," "); //食物数量 //根据菜单的名字查找相应的价钱 CString SQLstr; SQLstr="select * from ServerInfo where ServerName='"; SQLstr=SQLstr+ServerNameInBillList; SQLstr=SQLstr+"'"; if(!m_ServerInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE,SQLstr)) { MessageBox("打开数据库失败!","数据库错误",MB_OK); return; } float nMoney=m_ServerInfoSet.m_ServerPrice;//得到价钱 m_ServerInfoSet.Close();//关闭数据库 ////////////////////////////////////////////////////////////////////////// ///计算总数 long serverNum=0; serverNum=atoi(ServerNumInBillList);//食物数量 MoneySum=MoneySum+nMoney*serverNum; } ////将计算得到的总数再乘以折扣率 m_DefaultSum=MoneySum;//设置缺省的总数 float rebate=0.00f; CString strText; Rebate.UpdateData(true); Rebate.GetWindowText(strText); if(strText=="") { MessageBox("请输入折扣率!","数据为空错误",MB_OK); return; } char* sTemp=strText.GetBuffer(strText.GetLength()); rebate=atof(sTemp); MoneySum=m_DefaultSum*rebate;//乘以折扣率 CString strSum=""; strSum.Format("%6.00f",MoneySum); Sum.SetWindowText(strSum);//显示总数 //################################################################# } void CChooseServer::OnDelete() { // TODO: Add your control notification handler code here int nCount=ServerBillList.GetCount(); if(nCount==0) {//当前记录为空 MessageBox("当前没有删除的项目!","数据为空错误",MB_OK); Sum.SetWindowText("0"); return; } int nCurSel=ServerBillList.GetCurSel(); if(nCurSel==-1) {//没有选择一种菜 MessageBox("你应该选择一种要删除的服务项目!","数据为空错误",MB_OK); return; } else { ServerBillList.DeleteString(nCurSel); } /////删除以后从新计算帐总数 int nNum=ServerBillList.GetCount(); float nMoney=0.00f; for(int i=0;i<nNum;i++) { CString strItemText=""; ServerBillList.GetText(i,strItemText);//得到项目文本 char* str=strItemText.GetBuffer(strItemText.GetLength()); char* strServerName,*strServerNum; strServerName=strtok(str," ");//得到项目的名字 strServerNum=strtok(NULL," ");//得到服务项目的数目 CString SQLstr; SQLstr="select * from ServerInfo where ServerName='"; SQLstr=SQLstr+strServerName; SQLstr=SQLstr+"'"; if(!m_ServerInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE,SQLstr)) { MessageBox("打开数据库失败!","数据库错误",MB_OK); return; } float nPrice=m_ServerInfoSet.m_ServerPrice;//得到价钱 m_ServerInfoSet.Close();//关闭数据库 //////计算总数 long nServerNum=atoi(strServerNum); nMoney=nMoney+nPrice*nServerNum; } //显示更新后的总数 m_DefaultSum=nMoney;//设置缺省的总数 CString strShowText,strReabte; Rebate.GetWindowText(strReabte); char* s=strReabte.GetBuffer(strReabte.GetLength()); double n=atof(s); strShowText.Format("%6.00f",m_DefaultSum*n); Sum.SetWindowText(strShowText); } void CChooseServer::OnRadio() { // TODO: Add your control notification handler code here this->UpdateData(true); if(m_PaidType==0) { bStriked=true; Paid.EnableWindow(true); } if(m_PaidType==1) { bStriked=false; Paid.EnableWindow(false); } } void CChooseServer::OnUpdatedata() { // TODO: Add your control notification handler code here float MoneySum=0.00f; float rebate=0.00f; CString strText; Rebate.GetWindowText(strText);//得到折扣率文本 if(strText=="") { MessageBox("请输入折扣率!","数据为空错误",MB_OK); return; } char* sRebateTemp=strText.GetBuffer(strText.GetLength()); rebate=atof(sRebateTemp);//转变折扣率 MoneySum=m_DefaultSum*rebate; CString strSum=""; strSum.Format("%6.00f",MoneySum); Sum.SetWindowText(strSum);//显示总数 }